package com.woniu.supermarket.web;

import com.github.pagehelper.PageInfo;
import com.woniu.supermarket.result.ResultResponse;
import com.woniu.supermarket.service.ISalesReturnService;
import com.woniu.supermarket.vo.SalesReturnVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("salesReturn")
@Api(value = "销售退货单操作")
@Slf4j
public class SalesReturnController {


    @Autowired
    ISalesReturnService iSalesReturnService;

    @GetMapping("/showSalesReturn")
    @ApiOperation(value = "分页查询操作")
    public ResultResponse<PageInfo<SalesReturnVo>> showSalesReturn(@ApiParam(name = "now",value = "当前页")@RequestParam(name = "now",defaultValue = "1")Integer now,
                                                                   @ApiParam(name = "size",value = "页大小")@RequestParam(name = "size",defaultValue = "3")Integer size,
                                                                   @ApiParam(name = "saleReturnCode",value = "退货单编码")@RequestParam(value = "saleReturnCode",defaultValue = "")String saleReturnCode){
        ResultResponse<PageInfo<SalesReturnVo>> result = null;
//        System.out.println("saleReturnCode=============="+saleReturnCode);
        try {
            PageInfo<SalesReturnVo> pageInfo = iSalesReturnService.findByCons(now, size, saleReturnCode);
            result = new ResultResponse<>(200,"查询销售退货订单成功",pageInfo);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询销售退货订单失败");
        }
        return result;
    }

    @PutMapping("/reset")
    @ApiOperation(value = "重置订单操作")
    public ResultResponse<Void> reset(@RequestBody SalesReturnVo salesReturn){
        ResultResponse<Void> result = null;
        try {
            iSalesReturnService.reset(salesReturn);
            result = new ResultResponse<>(200,"重置销售订单成功");
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"重置销售订单失败");
        }
        return result;
    }

}
